package com.meilai.project.dto.workflow;

import com.meilai.project.exception.CommonException;
import com.meilai.project.util.WorkFlowUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.log4j.Log4j2;

import java.io.Serializable;

/**
 * @author 张驰
 * @date 2020/6/3 11:47
 */

@Data
@ApiModel(value= "工作流_审批组装对象")
@Log4j2
public class WorkFlowCheckDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "审批节点")
    private String checkNodeId;
    @ApiModelProperty(value = "审批轮次索引")
    private Long curCheckIndex;
    @ApiModelProperty(value = "审批意见")
    private String opinion=null;
    @ApiModelProperty(value = "手写签名地址")
    private String sign_url=null;
    @ApiModelProperty(value = "业务表数据记录json")
    private String data_json=null;



    /**
     * 构造函数
     * @param checkNodeId 节点id
     * @param curCheckIndex 当前审批轮次
     */
    public WorkFlowCheckDTO(String checkNodeId, Long curCheckIndex) {
        this.checkNodeId = checkNodeId;
        this.curCheckIndex = curCheckIndex;
    }


    public WorkFlowCheckDTO(String checkNodeId, Long curCheckIndex, String data_json) {
        this.checkNodeId = checkNodeId;
        this.curCheckIndex = curCheckIndex;
        this.data_json = data_json;
    }

     /**
     * 构造函数
     * @param checkNodeId 节点id
     * @param curCheckIndex 当前审批轮次
     * @param opinion 审批意见
     * @param sign_url 签名路径
     */
    public WorkFlowCheckDTO(String checkNodeId, Long curCheckIndex, String opinion, String sign_url) {
        this.checkNodeId = checkNodeId;
        this.curCheckIndex = curCheckIndex;
        this.opinion = opinion;
        this.sign_url = sign_url;
    }

    public WorkFlowCheckDTO(String checkNodeId, Long curCheckIndex, String opinion, String sign_url, String data_json) {
        this.checkNodeId = checkNodeId;
        this.curCheckIndex = curCheckIndex;
        this.opinion = opinion;
        this.sign_url = sign_url;
        this.data_json = data_json;
    }

    public static WorkFlowCheckDTO getWorkFlowCheckDTO(String checkNodeId, String flow_json, String opinion, String sign_url, String data_json) {
        Long curCheckIndex = -1L;
        try{
            curCheckIndex = WorkFlowUtil.getCurCheckIndex(flow_json, checkNodeId);
        }catch (Exception e){
            log.error("构造审批入参实体失败！",e);
            throw new CommonException("审批失败，请联系管理员！");
        }
        return new WorkFlowCheckDTO(checkNodeId, curCheckIndex, opinion, sign_url, data_json);
    }

    public static WorkFlowCheckDTO getWorkFlowCheckDTO(String checkNodeId, String flow_json, String opinion, String sign_url) {
        Long curCheckIndex = -1L;
        try{
            curCheckIndex = WorkFlowUtil.getCurCheckIndex(flow_json, checkNodeId);
        }catch (Exception e){
            log.error("构造审批入参实体失败！",e);
            throw new CommonException("审批失败，请联系管理员！");
        }
        return new WorkFlowCheckDTO(checkNodeId, curCheckIndex, opinion, sign_url);
    }
}
